package com.dk.service.impl;

import com.dk.mapper.TabCategoryMapper;
import com.dk.mapper.TabRouteImgMapper;
import com.dk.mapper.TabRouteMapper;
import com.dk.mapper.TabSellerMapper;
import com.dk.pojo.TabCategory;
import com.dk.pojo.TabRoute;
import com.dk.pojo.TabRouteImg;
import com.dk.pojo.TabSeller;
import com.dk.service.RouteService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.omg.CORBA.ORB;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RouteServiceImpl implements RouteService {
    @Autowired
    private TabRouteMapper tabRouteMapper;
    @Autowired
    private TabSellerMapper tabSellerMapper;
    @Autowired
    private TabCategoryMapper tabCategoryMapper;
    @Autowired
    private TabRouteImgMapper tabRouteImgMapper;

    @Override
    public PageInfo<TabRoute> selectByname(String rname, Integer rflag, Integer pageNumber, Integer pageSize) {
        PageHelper.startPage(pageNumber, pageSize);
        List<TabRoute> a = tabRouteMapper.selectBname(rname, rflag);
        PageInfo<TabRoute> tabRoutePageInfo = new PageInfo<>(a);
        return tabRoutePageInfo;
    }

    @Override
    public List<TabSeller> select() {
        List<TabSeller> tabSellers = tabSellerMapper.selectByExample(null);

        return tabSellers;
    }

    @Override
    public List<TabCategory> selectTable() {
        List<TabCategory> categories = tabCategoryMapper.selectByExample(null);


        return categories;
    }

    @Override
    public boolean insertinto(TabRoute tabRoute) {
        int insert = tabRouteMapper.insert(tabRoute);
        return insert < 0;
    }

    @Override
    public TabRoute selectByrid(Integer rid) {
        TabRoute tabRoute = tabRouteMapper.selectByPrimaryKey(rid);

        return tabRoute;
    }

    @Override
    public boolean updateInfo(TabRoute tabRoute) {
        int i = tabRouteMapper.updateByPrimaryKeySelective(tabRoute);
        return i < 0;
    }

    @Override
    public boolean deleteByid(Integer id) {
        int i = tabRouteMapper.deleteByPrimaryKey(id);
        return i < 0;
    }

    @Override
    public boolean addimginfo(String[] split, TabRouteImg t) {

        int a = tabRouteImgMapper.insertBy(split, t.getRid());
        return a > 0;
    }
}
